package com.boruishangge.common.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.launcher.ARouter;
import com.boruishangge.common.R;
import com.boruishangge.common.databinding.TabarHomeViewBinding;


/**
 * 首页的tab bar
 * Created by wuaomall@gmail.com on 2019/5/6.
 */

public class TabbaHomeView extends LinearLayout implements View.OnClickListener {
    private OnCheckedChangeListener mChangeListener;

    private TabarHomeViewBinding binding;
    private Context mconext;

    private boolean isshowError = false;

    public TabbaHomeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mconext = context;
        LayoutInflater inflater = LayoutInflater.from(context);
        binding = DataBindingUtil.inflate(inflater, R.layout.tabar_home_view, this, true);

        binding.llyHomeLoan.setOnClickListener(this);
        binding.llyHomeFind.setOnClickListener(this);
        binding.llyHomeMem.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        int index = -1;
        if (v == binding.llyHomeLoan) {
            index = 0;
        } else if (v == binding.llyHomeFind) {
            index = 1;
        } else if (v == binding.llyHomeMem) {
            index = 2;
        } else {
            index = 3;
        }

            showView(index);
            setSelectTab(index);

    }


    private void showView(int index) {
        if (index == 0) {
            binding.tvHomeLoan.setTextColor(mconext.getResources().getColor(R.color.color_1D81FF));
            binding.tvHomeFind.setTextColor(mconext.getResources().getColor(R.color.color_B8B8B8));
            binding.tvHomeMem.setTextColor(mconext.getResources().getColor(R.color.color_B8B8B8));


//            binding.ivHomeLoan.setBackground(mconext.getResources().getDrawable(R.mipmap.icon_borrowselected));
//            binding.ivHomeFind.setBackground(mconext.getResources().getDrawable(R.mipmap.icon_find_default));
//            binding.ivHomeMem.setBackground(mconext.getResources().getDrawable(R.drawable.no_member));


        } else if (index == 1) {
            binding.tvHomeLoan.setTextColor(mconext.getResources().getColor(R.color.color_B8B8B8));
            binding.tvHomeFind.setTextColor(mconext.getResources().getColor(R.color.color_1D81FF));
            binding.tvHomeMem.setTextColor(mconext.getResources().getColor(R.color.color_B8B8B8));

//            binding.ivHomeLoan.setBackground(mconext.getResources().getDrawable(R.mipmap.icon_borrowdefault));
//            binding.ivHomeFind.setBackground(mconext.getResources().getDrawable(R.mipmap.icon_findselected));
//            binding.ivHomeMem.setBackground(mconext.getResources().getDrawable(R.drawable.no_member));


        } else if (index == 2) {
            binding.tvHomeLoan.setTextColor(mconext.getResources().getColor(R.color.color_B8B8B8));
            binding.tvHomeFind.setTextColor(mconext.getResources().getColor(R.color.color_B8B8B8));
            binding.tvHomeMem.setTextColor(mconext.getResources().getColor(R.color.color_1D81FF));

//            binding.ivHomeLoan.setBackground(mconext.getResources().getDrawable(R.mipmap.icon_borrowdefault));
//            binding.ivHomeFind.setBackground(mconext.getResources().getDrawable(R.mipmap.icon_find_default));
//            binding.ivHomeMem.setBackground(mconext.getResources().getDrawable(R.drawable.member2));

        }
    }

    public void setSelectTab(int index) {
        if (index != 3) {

                showView(index);
        }
        if (mChangeListener != null) {
            mChangeListener.onCheckedChanged(index);
        }
    }
    public interface OnCheckedChangeListener {
        void onCheckedChanged(int index);
    }
    public void setOnCheckedChangeListener(OnCheckedChangeListener changeListener) {
        this.mChangeListener = changeListener;
    }


}
